package com.superman.supermarket.client.composite.preorder.coupon;

import java.util.Map;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.superman.mvpframe.client.widget.toggle.ToggleItem;
import com.superman.supermarket.client.composite.IUIModule;
import com.superman.supermarket.client.composite.storecoupon.StoreCouponModule;
import com.superman.supermarket.client.constant.StoreCouponConstants;

/**
 * 优惠券选择模块
 * 
 * @author superman
 * @version 2018年8月19日上午10:51:25
 */
public class CouponChooseCellModule extends ToggleItem implements IUIModule {

	private class PreorderCouponChooseCellModule extends StoreCouponModule {

		public PreorderCouponChooseCellModule() {
			wrapperpanel.getElement().getStyle().setProperty("background", "#e31436");

			wrapperpanel.getElement().getStyle().setProperty("color", "#fff");
			namehtml.getElement().getStyle().setProperty("color", "#fff");
			limithtml.getElement().getStyle().setProperty("color", "#fff");
			timehtml.getElement().getStyle().setProperty("color", "#fff");
			getbtn.getElement().getStyle().setProperty("color", "#fff");
			getbtn.setText("使用");

		}

		public void setButtonText(String string) {
			getbtn.setText(string);
		}

		@Override
		public void setData(Map<String, Object> map) {
			String nameStr = String.valueOf(map.get("NAME"));
			namehtml.setText(nameStr);

			// 限制类型
			int limitType = (int) Double.parseDouble(String.valueOf(map.get("SCENE_TYPE")));
			limithtml.setText(StoreCouponConstants.getLimitDescByType(limitType));

			DateTimeFormat sdtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
			DateTimeFormat edtf = DateTimeFormat.getFormat("yyyy-MM-dd");
			String startTime = String.valueOf(map.get("USE_START"));
			String endTime = String.valueOf(map.get("USE_END"));
			String timeStr = edtf.format(sdtf.parse(startTime)) + "至" + edtf.format(sdtf.parse(endTime));
			timehtml.setText(timeStr);
		}
	}

	private Map<String, Object> map;

	private PreorderCouponChooseCellModule preorderCouponChooseCellModule;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月19日 上午10:51:28
	 */
	public CouponChooseCellModule() {
		preorderCouponChooseCellModule = new PreorderCouponChooseCellModule();
		initWidget(preorderCouponChooseCellModule);

	}

	@Override
	public void changeStyle() {
		preorderCouponChooseCellModule.setButtonText("已选择");
	}

	@Override
	public Map<String, Object> getData() {
		return map;
	}

	@Override
	public void resetDefaultStyle() {
		preorderCouponChooseCellModule.setButtonText("使用");

	}

	@Override
	public void setData(Map<String, Object> map) {
		this.map = map;
		preorderCouponChooseCellModule.setData(map);
	}

}
